package com.contory.ssn_lgnd.app.maingame;

import java.util.ArrayList;
import java.util.LinkedList;

import android.util.Log;

import com.contory.ssn_lgnd.framework.math.Vector2;

public class PYellowBulletSocket {
	final Player p;
	Vector2 nDir;
	
	public PYellowBulletSocket(Player player){
		this.p = player;
		nDir = new Vector2();
	}
	
	public void fire(LinkedList<ColiObjPtr> targetBuffer, int fireCount, ParticleEffect ptcEft){
		int bufferCount = targetBuffer.size();
		if(bufferCount == 0 || fireCount == 0)
			return;
		int mid = bufferCount / 2;
		nDir.set(targetBuffer.get(mid).getPosX(), targetBuffer.get(mid).getPosY());
		nDir.sub(p.bodyView.x, p.bodyView.y);
		nDir.nor();
		int sign = 1;
		if((p.bodyView.x > targetBuffer.get(mid).getPosX() && p.bodyView.y > targetBuffer.get(mid).getPosY())||
		(p.bodyView.x < targetBuffer.get(mid).getPosX() && p.bodyView.y < targetBuffer.get(mid).getPosY())	){
			sign = -1;
		}
		float deltaRot = sign * (float)(Math.PI / 2) / (fireCount-1);
		nDir.rotate(-sign * (float)(Math.PI / 4));
		for(int i = 0, j = 0; i < fireCount; i++){
			p.fire.fire(new PYellowBullet(p.bodyView.x, p.bodyView.y, p.cm, targetBuffer.get(j), nDir, ptcEft));
			nDir.rotate(deltaRot);
			if(j < bufferCount-1)
				j++;
		}
	}
}
